package com.example.demo01.Controller;


import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.util.HexUtil;
import com.example.demo01.Socket.Client.NettyClient;
import com.example.demo01.Utils.FactoryPacketInstruction;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

import  cn.hutool.core.util.StrUtil;

import static java.nio.ByteOrder.BIG_ENDIAN;

@Slf4j
@RestController
@RequestMapping("/test")
@AllArgsConstructor
public class TestController {





    private final FactoryPacketInstruction factoryPacketInstruction;


    private NettyClient client;


    @RequestMapping("/test02")
    public void test02(String msg){

        log.info("msg "+msg);
        client.send("DX01",msg);
    }

    @RequestMapping("/test01")
    public void test01(){


//        byte[] bytes="DX01".getBytes(StandardCharsets.UTF_8);
//
//        for (byte b : bytes) {
//
//            log.info(String.valueOf(b));
//        }

//        byte[] bytes2=StrUtil.bytes("DX01",StandardCharsets.UTF_8);
//
//
//        log.info(HexUtil.encodeHexStr(bytes2));
//        log.info(HexUtil.encodeHexStr("DX01",StandardCharsets.UTF_8));


        short len=13;

        byte[] b2=ByteUtil.shortToBytes(len, BIG_ENDIAN);
        String hex=HexUtil.encodeHexStr(b2);
        log.info(hex);



        byte[] bl= HexUtil.decodeHex(hex);

        log.info("////");







//
//        for (byte b : bytes2) {
//
//            log.info(String.valueOf(b));
//        }
//
//        log.info(StrUtil.str(bytes2,StandardCharsets.UTF_8));
//       IPacketInstruction packetInstruction =  factoryPacketInstruction.getPacketInstruction("DX01");
//
//       log.info(packetInstruction.getTelNo());
    }
}
